﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Data;
using Business;

public partial class Default1 : @base {
    protected void Page_Load(object sender, EventArgs e) {
       
    }
    /// <summary>
    /// Handles the Authenticate event of the Login control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Web.UI.WebControls.AuthenticateEventArgs"/> instance containing the event data.</param>
    /// <return>
    /// athentication true if the user login data match, false otherwise
    /// </return>
    protected void Login_Authenticate(object sender, AuthenticateEventArgs e) {
        UserLogin_Data userlog = new UserLogin_Data();
        UserLogin_Business objlogin = new UserLogin_Business();
        Encryption objenc = new Encryption();
        AdminLogin_Data adminlog = new AdminLogin_Data();
        adminlog.UserName = Login1.UserName;
        AdminLogin_Business admlogin = new AdminLogin_Business();
        adminlog.Password = objenc.EncryptString(Login1.Password);
        //retreive username and encrypted password from the textbox 
        userlog.UserName = Login1.UserName;
        userlog.Password = objenc.EncryptString(Login1.Password);

        if (admlogin.AdminLogin(adminlog).Equals(true))
        {
            e.Authenticated = true;
            USERNAME = Login1.UserName;
            Login1.DestinationPageUrl = "admin/Home.aspx";
            BindUserDetails();
            //("admin/Home.aspx");
        }
        else if (objlogin.UserLogin(userlog).Equals(true))
        {

            e.Authenticated = true;

            //Create new session of "username"
            //thao  Session["username"] = Login1.UserName;

            USERNAME = Login1.UserName;
            Session["treeview"] = 1;
            BindUserDetails();
            BindClientDetails();
            // BindClientDetails();


            //CheckAdmin_Data checkadmin = new CheckAdmin_Data();
            //CheckAdmin_Business objadmin = new CheckAdmin_Business();
            //checkadmin.UserName = Login1.UserName;
            //if (objadmin.CheckAdmin(checkadmin).Equals(true)) {
            ////enable administration mode then go to admin/Home.aspx
            //} else {
            //    CheckUser_Data checkuser = new CheckUser_Data();
            //    CheckUser_Business objuser = new CheckUser_Business();
            //    checkadmin.UserName = Login1.UserName;
            //    if (objuser.CheckUser(checkuser).Equals(true)) {
            //    //enable admin role else enable staff role
            //    }
            //}
            //Business.OilReport.client_Oil_Report cor = new Business.OilReport.client_Oil_Report();
            //cor.Page_Load(sender, e);
            Oil_Report cor = new Oil_Report();
            cor.proceed_oil();
            // cor.;
        }
        else
        {
            e.Authenticated = false;
        }
    }
}
